﻿	<!DOCTYPE html>
	<html lang="en">
	<head>


	<!-- TEAM STATUS -->
	<!--/HEADER -->

	<!-- PAGE -->

	<!-- /SIDEBAR -->

	<!-- /SAMPLE BOX CONFIGURATION MODAL FORM-->

	<!-- /PAGE HEADER -->
	<!-- DATA TABLES -->
	<div class="row">
	<div class="col-md-12">
	<!-- BOX -->
	<div class="box border green">
	    <div class="box-title">
	        <h4><i class="fa fa-table"></i>角色列表</h4>
	        <div class="tools hidden-xs">
	            <a href="#box-config" data-toggle="modal" class="config">
	                <i class="fa fa-cog"></i>
	            </a>
	            <a href="javascript:;" class="reload">
	                <i class="fa fa-refresh"></i>
	            </a>
	            <a href="javascript:;" class="collapse">
	                <i class="fa fa-chevron-up"></i>
	            </a>
	            <a href="javascript:;" class="remove">
	                <i class="fa fa-times"></i>
	            </a>
	        </div>
	    </div>
	    <div class="box-body">
	    <form role="form" >

	        <table id="datatable1" cellpadding="0" cellspacing="0" border="0" class="datatable table table-striped table-bordered table-hover">

	            <thead>
	                <tr>
	                    <th width="10">ID</th>
	                    <th width="100">角色名称</th>
	                    <th width="100">权限列表</th>
	                    <th width="300">状态</th>
	                    <th width="50">审核</th>
	                    <th width="50">管理员</th>

	                </tr>
	            </thead>
	            <tbody>
	            <?php foreach($result as $value){?>
	                <tr class="gradeX">

	                    <td><?php echo $value['id']?></td>
	                    <td filed="title" class="db_edit"><?php echo $value['name']?></td>
	                    <td  filed="content"class="db_edit"><?php echo $value['power']?></td>
	                    <td filed="type" class="db_edit"><?php echo $value['state']?></td>

	                    <td>

	                    <button type="button" tp class="btn <?php echo($value['auditing']==1)?'btn-success':'btn-danger'?> bnt-xs"><i class="fa <?php echo $value['auditing']==1?'fa-check':'fa-times' ?>"></i></button>
	                    </td>
	                    <td>
	                        <a href="index.php?c=news&a=edit&admin=1&id=<?php echo $value['id']?>" class="btn btn-info"><i class="fa fa-pencil-square-o"></i> 编辑</a>

	                        <a href="index.php?c=news&a=del&admin=1&id=<?php echo $value['id']?>" onclick="return confirm('真的要删除吗？')" class="btn btn-2g btn-danger"><i class="fa fa-trash-o"></i> 删除</a>

	                    </td>

	                </tr>
	                <?php } ?>


	            </tbody>

	        </table>
	    <div class="row"><div class="col-sm-12">
	         <div class="pull-left">
	            <div class="dataTables_info" id="datatable1_info">Showing 1 to 10 of 57 entries</div>
	         </div>
	         <div class="pull-right">
	             <div class="dataTables_paginate paging_bs_full" id="datatable1_paginate">
	                   <ul class="pagination">


	                         <!--  <?php echo $pages; ?>
 -->
	                     </ul>
	                 </div>
	             </div>

	             <div class="clearfix"></div>
	             </div>
	          </div>

	        </form>


	    </div>
	</div>
	<!-- /BOX -->
	</div>
	</div>

	<script src="resources/admin/js/jquery/jquery-2.0.3.min.js""></script>
	<script type="text/javascript">







	$(function(){

	$('.pagination ').on('click','li a',function(){

	// var url = $(this).find('a').attr('href');
	var url = $(this).attr('href');
	//var url = 'index.php?admin=1&c=index&a=index';

	$.ajax({

	type:'get',
	url:url,
	dataType:'json',

	success:function(json){

	// console.console.log(json[0].title);
	//
	var html='';
	var result = json.result;
	for(var i in result){
	html+='<tr class="gradeX">';
	html+='<td><input type="checkbox" name="xz"></td>';
	html+='<td>'+result[i].id+'</td>';
	html+='<td filed="title" class="db_edit">'+result[i].title+'</td>';
	html+='<td filed="content" class="db_edit">'+result[i].content+'</td>';
	html+='<td filed="type" class="db_edit">'+result[i].type+'</td>';
	html+='<td>'+result[i].promulgator+'</td>';
	html+='<td>'+result[i].promulgator+'</td>';
	html+='<td>'+result[i].news_photo+'</td>';
	var auditing = (result[i].id)?'通过':'未通过';
	html+='<td>'+result[i].auditing+'</td>';
	html+='<td>';
	html+='<a href="index.php?c=news&a=edit&admin=1&id='+result[i].id+'" class="btn btn-info"><i class="fa fa-pencil-square-o"></i> 编辑</a>';

	html+='<a href="index.php?c=news&a=del&admin=1&id='+result[i].id+'" onclick="return confirm(真的要删除吗？)" class="btn btn-2g btn-danger">';
	html+='<i class="fa fa-trash-o"></i> 删除</a>';

	html+='</td>';
	html+='</tr>';
	}
	// console.log(html);
	$('tbody').html(html);//代替原来已经显示的数据
	$('.pagination').html(json.pages);
	}

	})
	return false;

	})
	//双击编辑列表数据
	//抓取类名等于db_edit的所有td标签绑定双击事件
	$('tbody ').on('dblclick','.db_edit',function(event) {

	var len = $('tbody :text').length;
	if(len>0){
	var val = $('tbody :text').val();

	$('tbody :text').parent().text(val);
	}
	//获取双击编辑的数据
	var txt = $(this).text();

	var inp = '<input type="text" value="'+txt+'"/>';
	//将要编辑的td内容替换成输入框的形式显示
	$(this).html(inp);
	//获取焦点事件
	$('tbody :text').focus();
	//绑定失去焦点事件
	$('tbody :text').blur(function(event) {
	//当input标签失去焦点则获取失去焦点的input标签val值
	var val = $(this).val();


	//获取要修改的字段名
	var filed = $(this).parent().attr('filed');

	var id =  $(this).parent().parent().find('td:first').text();
	//找到失去焦点input标签的父级，然后用编辑过的新数据替换掉父级（td）的文本内容，让显示效果恢复成原来的状态
	$(this).parent().text(val);

	$.ajax({
	type:'post',
	url:'index.php?c=news&a=edit&admin=1&id='+id,
	data:{
	val:val,
	filed:filed,
	},
	success:function(row){
	if(row>0){
	   alert('修改成功')
	}else{
	 alert('修改失败')
	}
	}
	})
	});
	});
	})



	</script>

